﻿using System;
using Garfield.Core.Runtime;
using PicoContainer;

namespace Garfield.Runtime.Pico
{
    class ObjectFactory : IObjectFactory
    {
        private readonly PlatformProvider provider;

        public ObjectFactory(PlatformProvider provider)
        {
            this.provider = provider;
        }

        public T CreateInstance<T>()
        {
            return CreateInstance<T>(null);
        }

        public T CreateInstance<T>(Action<T> intializer)
        {
            return (T) new ComponentAdapter(provider, Guid.NewGuid(), typeof(T), new IParameter[0]) { Initializer = intializer }.GetComponentInstance(provider.ServiceContext);
        }
    }
}
